package com.ficus.road.maintain.core.model.zh;

import com.ficus.road.maintain.core.model.RoadTypeEnum;
import lombok.Data;
import org.apache.commons.lang3.ObjectUtils;
import org.springframework.data.annotation.Id;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

/**
 * @author xiawen yang
 * @date 2022/4/1 下午2:41
 */
@Data
public class BasicBridgeZH {

    @Id
    private List<Bridge> cgs;

    private List<Bridge> gls;

    public List<BridgeInfo> convert2BridgeInfo(BasicBridgeZH zh) {
        Date date = new Date();
        List<BridgeInfo> res = new ArrayList<>();
        List<Bridge> cgs = zh.getCgs();
        cgs.stream().filter(item -> ObjectUtils.isNotEmpty(item.getBridgename())).forEach(bridge -> {
            String bridgeName = ObjectUtils.isEmpty(bridge.getBridgename()) ? "#" : bridge.getBridgename();
            String bridgeType = ObjectUtils.isEmpty(bridge.getBridgetype()) ? "#" : bridge.getBridgetype();
            String longitude = ObjectUtils.isEmpty(bridge.getCox()) ? "#" : bridge.getCox();
            String latitude = ObjectUtils.isEmpty(bridge.getCoy()) ? "#" : bridge.getCoy();
            String bridgeId = ObjectUtils.isNotEmpty(bridge.getBridgeid()) ? bridge.getBridgeid()
                    : bridgeName + "_" + bridgeType + "_" + longitude + "_" + latitude;
            BridgeInfo bridgeInfo = BridgeInfo.builder()
                    .id(bridgeId)
                    .bridgeName(bridge.getBridgename())
                    .bridgeType(bridge.getBridgetype())
                    .security(bridge.getSecurity())
                    .unit(bridge.getSection())
                    .company(bridge.getCompany())
                    .roadName(bridge.getRoadname())
                    .roadType(RoadTypeEnum.HIGHWAY)
                    .isSpecial(bridge.getIsspecial())
                    .isOverpass(bridge.getIsoverpass())
                    .techLevel(bridge.getTechlevel())
                    .longitude(bridge.getCox())
                    .latitude(bridge.getCoy())
                    .modificationTime(date)
                    .build();
            res.add(bridgeInfo);
        });
        List<Bridge> gls = zh.getGls();
        gls.stream().filter(item -> ObjectUtils.isNotEmpty(item.getBridgename())).forEach(bridge -> {
            String bridgeName = ObjectUtils.isEmpty(bridge.getBridgename()) ? "#" : bridge.getBridgename();
            String bridgeType = ObjectUtils.isEmpty(bridge.getBridgetype()) ? "#" : bridge.getBridgetype();
            String longitude = ObjectUtils.isEmpty(bridge.getCox()) ? "#" : bridge.getCox();
            String latitude = ObjectUtils.isEmpty(bridge.getCoy()) ? "#" : bridge.getCoy();
            BridgeInfo bridgeInfo = BridgeInfo.builder()
                    .id(ObjectUtils.isNotEmpty(bridge.getBridgeid()) ? bridge.getBridgeid()
                            : bridgeName + "_" + bridgeType + "_" + longitude + "_" + latitude)
                    .bridgeName(bridge.getBridgename())
                    .bridgeType(bridge.getBridgetype())
                    .security(bridge.getSecurity())
                    .unit(bridge.getSection())
                    .company(bridge.getCompany())
                    .roadName(bridge.getRoadname())
                    .roadType(RoadTypeEnum.DIRECT)
                    .isSpecial(bridge.getIsspecial())
                    .isOverpass(bridge.getIsoverpass())
                    .techLevel(bridge.getTechlevel())
                    .longitude(bridge.getCox())
                    .latitude(bridge.getCoy())
                    .modificationTime(date)
                    .build();
            res.add(bridgeInfo);
        });
        return res;
    }

    @Data
    public static class Bridge {

        private String bridgeid;
        /**
         * 桥梁名称
         */
        private String bridgename;
        /**
         * 桥梁类型
         */
        private String bridgetype;
        /**
         * 安全受控
         */
        private String security;
        /**
         * 所属标段
         */
        private String section;
        /**
         * 养护公司
         */
        private String company;
        /**
         * 所在道路
         */
        private String roadname;

        private String isspecial;

        private String isoverpass;

        private String techlevel;

        private String coy;

        private String cox;

        private String buildstatus;

        private String filepath;

        private Double bridgearea;

        private Double bridgewidth;
    }
}
